package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.common.model.LoginUser;
import com.ruoyi.system.domain.PmsPlanVo;
import com.ruoyi.system.domain.PmsSkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.PmsPlanMapper;
import com.ruoyi.system.domain.PmsPlan;
import com.ruoyi.system.service.IPmsPlanService;

/**
 * 采购需求Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@Service
public class PmsPlanServiceImpl implements IPmsPlanService
{
    @Autowired
    private PmsPlanMapper pmsPlanMapper;
    @Autowired
    private TokenService tokenService;


    /**
     * 查询采购需求
     *
     * @param id 采购需求主键
     * @return 采购需求
     */
    @Override
    public PmsPlan selectPmsPlanById(Long id)
    {
        return pmsPlanMapper.selectPmsPlanById(id);
    }

    /**
     * 查询采购需求列表
     *
     * @param pmsPlan 采购需求
     * @return 采购需求
     */
    @Override
    public List<PmsPlan> selectPmsPlanList(PmsPlan pmsPlan)
    {
        return pmsPlanMapper.selectPmsPlanList(pmsPlan);
    }

    /**
     * 新增采购需求
     *
     * @param pmsSkuInfo 采购需求
     * @return 结果
     */
    @Override
    public R insertPmsPlan(PmsSkuInfo pmsSkuInfo)
    {
        PmsPlan pmsPlan = pmsPlanMapper.selectPmsPlanById(pmsSkuInfo.getSkuId());
        if (pmsPlan != null){
            return R.fail("该商品已被添加");
        }
        Long skuId = pmsSkuInfo.getSkuId();
        LoginUser loginUser = tokenService.getLoginUser();
        String username = loginUser.getUsername();
        int i = pmsPlanMapper.insertPmsPlan(skuId, username);
        return R.ok(i);
    }

    /**
     * 修改采购需求
     *
     * @param pmsPlan 采购需求
     * @return 结果
     */
    @Override
    public int updatePmsPlan(PmsPlan pmsPlan)
    {
        return pmsPlanMapper.updatePmsPlan(pmsPlan);
    }

    /**
     * 批量删除采购需求
     *
     * @param ids 需要删除的采购需求主键
     * @return 结果
     */
    @Override
    public int deletePmsPlanByIds(Long[] ids)
    {
        return pmsPlanMapper.deletePmsPlanByIds(ids);
    }

    /**
     * 删除采购需求信息
     *
     * @param id 采购需求主键
     * @return 结果
     */
    @Override
    public int deletePmsPlanById(Long id)
    {
        return pmsPlanMapper.deletePmsPlanById(id);
    }

    /**
     * 查询采购需求列表
     *
     * @param pmsPlanVo
     * @return
     */
    @Override
    public List<PmsPlanVo> selectPmsPlanVoList(PmsPlanVo pmsPlanVo) {
        return pmsPlanMapper.selectPmsPlanVoList(pmsPlanVo);
    }
}
